Part Number Hot Search : 
IL78L05 1100A SMS24 ZURUY56W 30R500 2SC23 5925B 160128A
Product Description
Full Text Search
 

To Download AN4013 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  january 2015 docid022500 rev 4 1/37 1 AN4013 application note stm32f0, stm32f1, stm32f2, stm32f4, stm32l1 series, stm32f30x, stm32f3x8, stm32f373 lines timer overview introduction the purpose of this document: is detailed hereafter; ? present an overview of the timer peripherals in the stm32f0, stm32f1, stm32f2, stm32f4 and stm32l1 microcontroller series, stm32f30x and stm32f3x8, stm32f37x microcontrollers lines . stm32f30x corresponds to stm32f301, stm32f302 and stm32f303 lines. ? describe the various modes and specific features of the timers, such as clock sources. ? explain how to use the available modes and features. ? explain how to compute the time base in each configuration. ? describe the timer synchronization sequences and the advanced features for motor control applications, in addition to the general-purpose timer modes. for each mode, typical configurations are presented and examples of how to use the modes are provided. in the rest of this document (unless otherwise specified), the term stm32xx is used to refer to the products listed in table 1 . table 1. applicable products type applicable products microcontrollers stm32f0, stm32f1, stm32f2, stm32f4, stm32l1 series. stm32f301, stm32f302, stm32f303, stm32f3x8, stm32f373 lines. www.st.com
contents AN4013 2/37 docid022500 rev 4 contents 1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 general-purpose timer modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1 clock input sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.1 internal clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.2 external clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 time base generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 timer input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 timer output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.5 timer pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.6 timer one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.7 timer asymmetric pwm mode available for stm32f30x and stm32f3x8 lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.8 timer combined pwm mode available for stm32f30x and stm32f3x8 lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.9 retriggerable one pulse mode available for stm32f30x and stm32f3x8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 timer synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1 timer system link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.2 master configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.3 slave configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4 advanced features for motor control . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.1 signal generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.2 combined three-phase pwm mode available for stm32f30x and stm32f3x8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3 specific features for motor control applications . . . . . . . . . . . . . . . . . . . . 27 4.3.1 complementary signal and dead time feature . . . . . . . . . . . . . . . . . . . . 27 4.3.2 break input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3.3 locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.3.4 specific features for feedback measurement . . . . . . . . . . . . . . . . . . . . 30 5 specific applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
docid022500 rev 4 3/37 AN4013 contents 3 5.1 infrared application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 5.2 3-phase ac and pmsm control motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 5.3 six-step mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
list of tables AN4013 4/37 docid022500 rev 4 list of tables table 1. applicable products. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. stm32 family timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 table 3. timer features overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 table 4. advanced timer configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 table 5. behavior of timer outputs versus break1 and break2 inputs . . . . . . . . . . . . . . . . . . . . . . . 29 table 6. locking levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 table 7. document revision history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
docid022500 rev 4 5/37 AN4013 list of figures 5 list of figures figure 1. asymmetric pwm mode versus center aligned pwm mode . . . . . . . . . . . . . . . . . . . . . . . 17 figure 2. combined pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 3. retriggerable opm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 figure 4. timer system link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 figure 5. combined three-phase pwm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 figure 6. two signals are generated with insertion of a dead time . . . . . . . . . . . . . . . . . . . . . . . . . . 27 figure 7. position at x4 resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 figure 8. position at x2 resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 figure 9. output waveform of a typical hall sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 10. commutation sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
overview AN4013 6/37 docid022500 rev 4 1 overview stm32 devices use various types of timers, with the following features for each: ? general-purpose timers are used in any application for output compare (timing and delay generation), one-pulse mode, input capture (for external signal frequency measurement), sensor interface (encoder, hall sensor)... ? advanced timers : these timers have the most features. in addition to general purpose functions, they include several features related to motor control and digital power conversion applications: three complementary signals with deadtime insertion, emergency shut-down input. ? one or two channel timers : used as general-purpose timers with a limited number of channels. ? one or two channel timers with complementary output : same as previous type, but having a deadtime generator on one channel. this allows having complementary signals with a time base independent from the advanced timers. ? basic timers have no input/outputs and are used either as timebase timers or for triggering the dac peripheral. table 2 summarizes the stm32 family timers. table 3 presents a general overview of timer features.
docid022500 rev 4 7/37 AN4013 overview 36 note: stm32f30x and stm32f3x8 timers present several new modes: asymmetric mode, combined mode, one retriggerable mode, combined 3 pwm mode and a second break input, these modes are available only for these families. table 2. stm32 family timers timer type stm32f0 series stm32f101 /102/103/ 105/107 lines stm32f100 value line stm32l1 series stm32f2 and stm32f4 series stm32f30x and stm32f3x8 stm32f37x lines advanced tim1 tim1 tim1 - tim1 tim1 - - tim8 - - tim8 tim8 - tim20 (1) general purpose 16-bit - tim2 tim2 tim2 - tim2 tim2 tim3 tim3 tim3 tim3 tim3 tim3 tim3 - tim4 tim4 tim4 tim4 tim4 tim4 - tim5 tim5 - - - tim5 - - - - - - tim19 32-bit tim2 - - - tim2 tim2 tim2 - - - - tim5 tim5 basic tim6 tim6 tim6 tim6 tim6 tim6 tim6 - tim7 tim7 tim7 tim7 tim7 tim7 - - - - - - tim18 1-channel - tim10 - tim10 tim10 - - - tim11 - tim11 tim11 - - - tim13 tim13 tim13 - tim13 tim14 tim14 tim14 tim14 - tim14 2-channel - tim9 tim9 tim9 - - - tim12 tim12 - tim12 - tim12 1-channel with one complementary output tim15 - tim15 - - tim15 tim15 - - - - - - - 2-channel with one complementary output tim16 - tim16 - - tim16 tim16 tim17 - tim17 - - tim17 tim17 1. tim20 is only available for stm32f303xdxe and stm32f398ve devices.
overview AN4013 8/37 docid022500 rev 4 table 3. timer features overview timer type counter resolution counter type dma channels comp. channels synchronization master config. slave config. advanced 16 bit up, down and center aligned yes 4 3 yes yes general-purpose 16 bit 32 bit (1) up, down and center aligned yes 4 0 yes yes basic 16 bit up yes 0 0 yes no 1-channel 16 bit up no 1 0 yes (oc signal) no 2-channel 16 bit up no 2 0 yes yes 1-channel with one complementary output 16 bit up yes 1 1 yes (oc signal) no 2-channel with one complementary output 16 bit up yes 2 1 no yes 1. tim2 and tim5 are 32-bit counter resolution in the stm32f2, stm32f4 series, stm32f303xb/c/d/e and stm32f3x8 devices.
docid022500 rev 4 9/37 AN4013 general-purpose timer modes 36 2 general-purpose timer modes general-purpose timers can be programmed to work in one of the following configurations. 2.1 clock input sources the timer can be synchronized by several clocks simultaneously: ? internal clock ? external clock ? external mode1 (ti1 or ti2 pins) ? external clock mode2 (etr pin) ? internal trigger clock (itrx) 2.1.1 internal clock the timer is clocked by default by the internal clock provided from the rcc. to select this clock source, the smcr_sms (if present) bits should be reset. 2.1.2 external clock the external clock timer is divided in two categories: ? external clock connected to ti1 or ti2 pins ? external clock connected to etr pin in these cases, the clock is provided by an external signal connected to tix pins or etr pin. the maximum external clock frequency should be verified. note: 1 in addition to all these clock sources, the timer should be clocked with the apbx clock. 2 the external clocks are not directly feeding the prescaler, but they are first synchronized with the apbx clock through dedicated logical blocks. external clock mode1 (ti1 or ti2 pins) in this mode the external clock will be applied on timer input ti1 pin or ti2 pin. to do this: 1. configure the timers to use the tix pin as input: a) select the pin to be used by writing ccxs bits in the timx_ccmr1 register. b) select the polarity of the input: for the stm32f100/101/102/103/105/107 lines: by writing ccxp in the timx_ccer register to select the rising or the falling edge; for the other series & lines: by writing ccxp and ccxnp in the timx_ccer register to select the rising/falling edge, or both edges (a) . a. for the stm32f100/101/102/103/105/107 lines, polarity selection for both edges can be achieved by using ti1f_ed, but only for ti1 input.
general-purpose timer modes AN4013 10/37 docid022500 rev 4 c) enable the corresponding channel by setting the ccex bit in the timx_ccer register. 2. select the timer tix as the trigger input source by writing ts bits in the timx_smcr register. 3. select the external clock mode1 by writing sms=111 in the timx_smcr register. external clock mode2 (etr pin) the external clock mode2 uses the etr pin as timer input clock. to use this feature: 1. select the external clock mode2 by writing ece = 1 in the timx_smcr register. 2. configure, if needed, the prescaler, the filter and the polarity by writing etps [1:0], etf [3:0] and etp in the timx_smcr register. internal trigger clock (itrx) this is a particular mode of timer synchronization. when using one timer as a prescaler for another timer, the first timer update event or output compare signal is used as a clock for the second one. 2.2 time base generator the timer can be used as a time base generator. depending on the clock, prescaler and auto reload, repetition counter (if present) parameters, the 16-bit timer can generate an update event from a nanosecond to a few minutes. for the 32-bit timer, the range is larger. example update event period the update event period is calculated as follows: update_event = tim_clk/((psc + 1)*(arr + 1)*(rcr + 1)) tim_clk = 72 mhz prescaler = 1 auto reload = 65535 no repetition counter rcr = 0 update_event = 72*106/((1 + 1)*(65535 + 1)*(1)) update_event = 549.3 hz where: tim_clk = timer clock input psc = 16-bit prescaler register arr = 16/32-bit autoreload register rcr = 16-bit repetition counter
docid022500 rev 4 11/37 AN4013 general-purpose timer modes 36 example external clock mode2 in this mode, the update event period is calculated as follows: update_event = etr_clk/((etr_psc)*(psc + 1)*(arr + 1)*(rcr + 1)) where etr_clk = the external clock frequency connected to etr pin. etr_clk = 100 khz prescaler = 1 etr_psc = 2 autoreload = 255 repetition counter = 2 update_event= 100*103/((2 + 1)* (1+ 1)*((255 + 1)*(2 + 1)) update_event = 21.7 hz example external clock mode1 in this mode, the update event period is calculated as follows: update_event = tix_clk/((psc + 1)*(arr + 1)*(rcr +1)) where tix_clk = the external clock frequency connected to ti1 pin or ti2 pin. tix_clk = 50 khz prescaler = 1 auto reload = 255 repetition counter = 2 update_event = 50 000/((1+ 1)*((255 + 1)*(2 + 1)) update_event = 32.55 hz example internal trigger clock (itrx) mode1 in this mode, the update event period is calculated as follows: update_event = itrx_clk/((psc + 1)*(arr + 1)*(rcr + 1)) where itrx_clk = the internal trigger frequency mapped to timer trigger input (trgi) itrx_clk = 8 khz prescaler = 1 auto reload = 255 repetition counter = 1 update_event = 8000/((1+ 1)*((255 + 1)*(1 + 1)) update_event = 7.8 hz depending on the counter mode, the update event is generated each: ? overflow, if up counting mode is used: the dir bit is reset in timx_cr1 register ? underflow, if down counting mode is used: the dir bit is set in timx_cr1 register ? overflow and underflow, if center aligned mode is used: the cms bits are different from zero.
general-purpose timer modes AN4013 12/37 docid022500 rev 4 the update event is generated also by: ? software, if the ug (update generation) bit is set in tim_egr register. ? update generation through the slave mode controller as the buffered registers (arr, psc, ccrx) need an update event to be loaded with their preload values, set the urs (update request source) to 1 to avoid the update flag each time these values are loaded. in this case, the update event is only generated if the counter overflow/underflow occurs. the update event can be also disabled by setting the bit udis (update disable) in the cr1 register. in this case, the update event is not generated, and shadow registers (arr, psc, ccrx) keep their value. the counter and the prescaler are reinitialized if the ug bit is set, or if a hardware reset is received from the slave mode controller. an interrupt or/ and a dma request can be generated when the uie bit or/and ude bit are set in the dier register. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries in the /project/stm32xx_stdperiph_examples/ tim/timebase folder. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3348-discovery\examples\tim\tim_timebase, ? projects\stm32f302r8-nucleo\examples\tim\tim_timebase, ? projects\stm32f3-discovery\examples\tim\tim_timebase, ? projects\stm32373c_eval\examples\tim\tim_timebase, ? projects\stm32303e_eval\examples\tim\tim_timebase and ? projects\stm32303c_eval\examples\tim\tim_timebase 2.3 timer input capture mode the timer can be used in input capture mode to measure an external signal. depending on timer clock, prescaler and timer resolution, the maximum measured period is deduced. to use the timer in this mode: 1. select the active input by setting the ccxs bits in ccmrx register. these bits should be different from zero, otherwise the ccrx register will be read only. 2. program the filter by writing the ic1f[3:0] bits in the ccmrx register, and the prescaler by writing the ic1psc[1:0] if needed. 3. program the polarity by writing the ccxnp/ccxp bits to select between rising, falling or both edges. the input capture module is used to capture the value of the counter after a transition is detected by the corresponding input channel. to get the external signal period, two consecutive captures are needed. the period is calculated by subtracting these two values. period = capture(1) /(timx_clk *(psc+1)*(icxpsc)*polarity_index(2)) the capture difference between two consecutive captures ccrx_tn and ccrx_tn+1: ? if ccrx_tn < ccrx_tn+1: capture = ccrx_tn+1 - ccrx_tn ? if ccrx_tn > ccrx_tn+1: capture = (arr_max - ccrx_tn) + ccrx_tn+1 the polarity index is 1 if the rising or falling edge is used, and 2 if both edges are used.
docid022500 rev 4 13/37 AN4013 general-purpose timer modes 36 particular case to facilitate the input capture measurement, the timer counter is reset after each rising edge detected on the timer input channel by: ? selecting tixfpx as the input trigger by setting the ts bits in the smcr register ? selecting the reset mode as the slave mode by configuring the sms bits in the smcr register using this configuration, when an edge is detected, the counter is reset and the period of the external signal is automatically given by the value on the ccrx register. this method is used only with channel 1 or channel 2. in this case, the input capture prescaler (icpsc) is not considered in the period computation. the period is computed as follows: period = ccrx /(timx_clk *(psc+1)* polarity_index(1)) the polarity index is 1 if rising or falling edge is used, and 2 if both edges are used. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries in the /project/stm32xx_stdperiph_examples/ tim/inputcapture folder. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3-discovery\examples\tim\tim_inputcapture, ? projects\stm32373c_eval\examples\timtim_inputcapture, ? projects\stm32303e_eval\examples\tim\tim_inputcapture and ? projects\stm32303c_eval\examples\tim\tim_inputcapture 2.4 timer output compare mode to control an output waveform, or to indicate when a period of time has elapsed, the timer is used in one of the following output compare modes. the main difference between these modes is the output signal waveform. ? output compare timing : the comparison between the output compare register ccrx and the counter cnt has no effect on the outputs. this mode is used to generate a timing base. ? output compare active : set the channel output to active level on match. the ocxref signal is forced high when the counter (cnt) matches the capture/compare register (ccrx). ? output compare inactive : set channel to inactive level on match. the ocxref signal is forced low when the counter (cnt) matches the capture/compare register (ccrx). ? output compare toggle : ocxref toggles when the counter (cnt) matches the capture/compare register (ccrx). ? output compare forced active/inactive : ocref is forced high (active mode) or low (inactive mode) independently from counter value.
general-purpose timer modes AN4013 14/37 docid022500 rev 4 to configure the timer in one of these modes: 1. select the clock source. 2. write the desired data in the arr and ccrx registers. 3. configure the output mode: a) select the output compare mode: timing / active / inactive / toggle. b) in case of active, inactive and toggle modes, select the polarity by writing ccxp in ccer register. c) disable the preload feature for ccx by writing ocxpe in ccmrx register. d) enable the capture / compare output by writing ccxe in ccmrx register. 4. enable the counter by setting the cen bit in the timx_cr1 register. 5. set the ccxie / ccxde bit if an interrupt / dma request is to be generated. timer output compare timing / toggle update rate computation ccx update rate = timx_counter_clk / ccrx ? if internal clock: timx_counter_clk = tim_clk / (psc + 1) ? if external clock mode2: timx_counter_clk = etr_clk / ((etr_psc)*(psc + 1)) ? if external clock mode1: timx_counter_clk = tix_clk/(psc + 1) ? if etrf used as clock source: trgi_clk = etr_clk / etr_psc ? if ti1fp1 used as clock source: trgi_clk = ti1_clk / ti1_psc ? if ti2fp2 used as clock source: trgi_clk = ti2_clk / ti2_psc ? if ti1_ed used as clock source: trgi_clk = ti1_ed_clk ? if itrx used as clock source: trgi_clk = itrx_clk timer output compare active/inactive delay computation ccx_delay = ccrx /timx_counter_clk ? if internal clock: timx_counter_clk = tim_clk / (psc + 1) ? if external clock mode2: timx_counter_clk = etr_clk / ((etr_psc)*(psc + 1)) ? if external clock mode1: timx_counter_clk = tix_clk/(psc + 1) ? if etrf used as clock source: trgi_clk = etr_clk / etr_psc ? if ti1fp1 used as clock source: trgi_clk = ti1_clk / ti1_psc ? if ti2fp2 used as clock source: trgi_clk = ti2_clk / ti2_psc ? if ti1_ed used as clock source: trgi_clk = ti1_ed_clk ? if itrx used as clock source: trgi_clk = itrx_clk for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/oc_toggle, /ocactive and /ocinactive folders.
docid022500 rev 4 15/37 AN4013 general-purpose timer modes 36 2.5 timer pwm mode the timer is able to generate pwm in edge-aligned mode or center-aligned mode independently on each channel, with a frequency determined by the value of the timx_arr register, and a duty cycle determined by the value of the timx_ccrx register. pwm mode 1 ? in up-counting, channelx is active as long as cnt< ccrx, otherwise it is inactive. ? in down-counting, channelx is inactive as long as cnt> ccrx, otherwise it is active pwm mode 2 ? in up-counting, channelx is inactive as long as cnt < ccrx, otherwise it is active. ? in down-counting, channelx is active as long as cnt > ccrx, otherwise it is inactive. note: active when ocref = 1, inactive when ocref = 0. to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. select the pwm mode (pwm1 or pwm2) by writing ocxm bits in ccmrx register. 3. program the period and the duty cycle respectively in arr and ccrx registers. 4. set the preload bit in ccmrx register and the arpe bit in the cr1 register. 5. select the counting mode: a) pwm edge-aligned mode: the counter must be configured up-counting or down- counting. b) pwm center aligned mode: the counter mode must be center aligned counting mode (cms bits different from '00'). 6. enable the capture compare. 7. enable the counter. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/pwm_output and /7pwm_output folders. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f303re-nucleo\examples\tim\tim_pwmoutput, ? projects\stm32f302r8-nucleo\examples\tim\tim_pwmoutput, ? projects\stm32f3-discovery\examples\tim\tim_pwmoutput, ? projects\stm32373c_eval\examples\tim\tim_pwmoutput, ? projects\stm32303e_eval\examples\tim\tim_pwmoutputand ? projects\stm32303c_eval\examples\tim\tim_pwmoutput
general-purpose timer modes AN4013 16/37 docid022500 rev 4 2.6 timer one pulse mode one pulse mode (opm) is a particular case of the input capture mode and the output compare mode. it allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length after a programmable delay. to configure the timer this mode: 1. configure the input pin and mode: a) select the tixfpx trigger to be used by writing ccxs bits in ccmrx register. b) select the polarity of the input pin by writing ccxp and ccxnp bits in ccer register. c) configure the tixfpx trigger for the slave mode trigger by writing ts bits in smcr register. d) select the trigger mode for the slave mode by writing sms = 110 in smcr register. 2. configure the output pin and mode: a) select the output polarity by writing ccyp bit in ccer register. b) select the output compare mode by writing ocym bits in ccmry register (pwm1 or pwm2 mode). c) set the delay value by writing in ccry register. d) set the auto reload value to have the desired pulse: pulse = timy_arr - timy_ccry. 3. select the one pulse mode by setting the opm bit in cr1 register, if only one pulse is to be generated. otherwise this bit should be reset. delay = ccry/(timx_clk/(psc + 1)) pulse-length = (arr - ccry)/(timx_clk/(psc + 1)) for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/onepulse folder. 2.7 timer asymmetric pwm mode available for stm32f30x and stm32f3x8 lines the asymmetric mode allows generating a center-aligned pwm signals with a programmable phase shift. for a dedicated channel, the phase shift and the pulse length are programmed using the two timx_ccrx register (timx_ccr1 and timx_ccr2 or timx_ccr3 and timx_ccr4), the frequency is determined by the value of the timx_arr register. so the asymmetric pwm mode can be selected independently on two channels by programming the ocxm bits in timx_ccmrx register: ? ocxm = 1110 to use the asymmetric pwm1, in this mode the output reference has the same behavior as in pwm1 mode. when the counter is counting up the output reference is identical to oc1/3ref, when the counter is down counting, the output reference is identical to oc2/4ref ? ocxm = 1111 to use the asymmetric pwm2, in this mode the output reference has the same behavior as in pwm2 mode. when the counter is counting up the output reference is identical to oc1/3ref, when the counter is down counting, the output reference is identical to oc2/4ref
docid022500 rev 4 17/37 AN4013 general-purpose timer modes 36 the following figure resumes the asymmetric behavior versus the center aligned pwm mode figure 1. asymmetric pwm mode versus center aligned pwm mode to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. select the asymmetric pwm mode (asymmetric pwm1 or asymmetric pwm2) by writing ocxm bits in ccmrx register. 3. program the period, the pulse length and the phase shift respectively in arr, ccrx and ccry registers. 4. select the counting mode: the asymmetric pwm mode is working only with center aligned mode: the counter mode must be center aligned counting mode (cms bits different from '00'). 5. enable the capture compare. 6. enable the counter. for more details on how to use the timer in this mode, refer to the examples provided in the stm32f30x standard peripheral libraries, in the /project/stm32f30x_stdperiph_examples/ tim/asymmetric folders. 069 3:0fhqwhudoljqhg$55 dqg &&5[  3:0fhqwhudoljqhg$55 dqg &&5\       $v\phwulf3:0fhqwhudoljqhg$55 &&5[ dqg&&5\ 
general-purpose timer modes AN4013 18/37 docid022500 rev 4 stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3-discovery\examples\tim\tim_asymetric, ? projects\stm32303e_eval\examples\tim\tim_asymetric ? projects\stm32303c_eval\examples\tim\tim_asymetric. 2.8 timer combined pwm mode available for stm32f30x and stm32f3x8 lines the combined mode allows generating edge or center aligned pwm signals with programmable delay and phase shift between respective pulses. to generate a combined signal, the timx_ccrx and timx_ccry must be used to program the delay and the phase shift, the frequency is determined by the value of the timx_arr register. the resulting signal (combined signal) is made of an or or and logical combination of two reference pwms. so the combined pwm mode can be selected independently on two channels by programming the ocxm bits in timx_ccmrx register: ? ocxm = 1100 to use the combined pwm1, in this case the combined output reference has the same behavior as in pwm mode 1. the combined output reference is the logical or between oc1/3ref and oc2/4ref ? ocxm = 1101 to use the combined pwm2,in this case the combined output reference has the same behavior as in pwm mode 2. the combined output reference is the logical and between oc1/2ref and oc2/4ref the following figures resume the combined mode figure 2. combined pwm mode 069 2&5hi3:0 2&5hi3:0 2&&5hi &rpelqhg3:0 2&5hi3:0 2&5hi3:0 2&&5hi &rpelqhg3:0
docid022500 rev 4 19/37 AN4013 general-purpose timer modes 36 to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. select the combined pwm mode (combined pwm1 or combined pwm2) by writing ocxm bits in ccmrx register. 3. program the period, the delay and the phase shift respectively in arr, ccrx and ccry registers. 4. select the counting mode: a) edge-aligned mode: the counter must be configured up-counting or down- counting. b) center aligned mode: the counter mode must be center aligned counting mode (cms bits different from '00') 5. enable the capture compare. 6. enable the counter. 2.9 retriggerable one pulse mode available for stm32f30x and stm32f3x8 the retriggerable one pulse mode is a one pulse mode with the particularity of: ? the pulse starts as soon as the trigger occurs (no programmable delay) ? the pulse is extended if a new trigger occurs before the previous one is completed if the counter is configured in up-counting mode, the corresponding ccrx must be set to 0, in this case the pulse length is determined by arr register. if the timer is configured in down-counting mode, the arr must be set to 0 in this case the pulse length is determined by ccrx register. as for the opm mode, there are two retriggerable one pulse mode, retriggerable opm mode 1 and retriggerable opm mode 2: ? retriggerable opm mode 1 is selected by setting the ocxm bits to 1000: ? in up-counting mode, channel is inactive until a trigger event is detected (on trgi signal), the comparison is performed like in pwm mode 1, then the channel becomes inactive again at the next update. ? in down-counting mode, channel is active until a trigger event is detected (on trgi signal), the comparison is performed like in pwm mode 1, then the channel becomes active again at the next update. ? retriggerable opm mode 2 i s selected by setting the ocxm bits to 1001: ? in up-counting mode, the channel is active until a trigger event is detected (on trgi signal), the comparison is performed like in pwm mode 2, then the channel becomes inactive again at the next update. ? in down-counting mode, the channel is inactive until a trigger event is detected (on trgi signal), the comparison is performed like in pwm mode 1, then the channel becomes inactive again at the next update.
general-purpose timer modes AN4013 20/37 docid022500 rev 4 the following figure presents an example of the retriggerable opm mode figure 3. retriggerable opm mode to configure the timer in this mode: 1. configure the input pin and mode: a) select the tixfpx trigger to be used by writing ccxs bits in ccmrx register. b) select the polarity of the input pin by writing ccxp and ccxnp bits in ccer register. c) configure the tixfpx trigger for the slave mode trigger by writing ts bits in smcr register. d) select the combined reset + trigger mode for the slave mode by writing sms = 1000 in smcr register. 2. configure the output pin and mode: a) select the output polarity by writing ccyp bit in ccer register. b) select the output compare mode by writing ocym bits in ccmry register (retriggerable opm mode 1 or retriggerable opm mode 2). c) set the pulse length value by writing in ccry register if the counter is down- counting or by writing in the arr if the counter is up-counting. for more details on using the timer in this mode, refer to the examples provided in the stm32f30x standard peripheral libraries, in the /project/stm32f30x_stdperiph_examples/ tim/retriggerable opm folder. 069 7uljjhu 2&[ 3xovhohqjwk 5hwuljjhudeohsxovhohqjwk 3xovhohqjwk 3xovhohqjwk
docid022500 rev 4 21/37 AN4013 timer synchronization 36 3 timer synchronization 3.1 timer system link stm32 timers are linked together internally for timer synchronization or chaining. each timer has several internal trigger inputs and outputs. these signals allow the timer to be connected with other timers. figure 4. timer system link 3.2 master configuration when a timer is selected as a master timer, the corresponding trigger output signal is used by the slave internal trigger (when configured). the trigger output can be selected from the following list: ? reset : the ug bit from the egr register is used as a trigger output (trgo). ? enable : the counter enable signal is used as a trigger output (trgo). it is used to start several timers at the same time, or to control a window in which a slave timer is enabled. ? update : the update event is selected as trigger output (trgo). for example, a master timer can be used as a prescaler for a slave timer. ? compare pulse : the trigger output sends a positive pulse when the cc1if flag is to be set (even if it was already high) as soon as a capture or a compare match occurs. ? oc1ref : oc1ref signal is used as trigger output (trgo). ? oc2ref : oc2ref signal is used as trigger output (trgo). ? oc3ref : oc3ref signal is used as trigger output (trgo). ? oc4ref : oc4ref signal is used as trigger output (trgo). 069  7uljjhu rxwsxw 7uljjhulqsxwv ,75 ,75 ,75 ,75 7,)3 7,)3 7,)(' ,75 75& 75*, 7uljjhu frqwuro 75*2 7,0[b&/. 7,0[
timer synchronization AN4013 22/37 docid022500 rev 4 to configure a timer in master mode: 1. configure your timer. 2. select the trigger output to be used, by writing the msm (master mode selection) bits in cr2 register. 3. enable the msm (master/slave mode) bit in the smcr register to allow a perfect synchronization between the current timer and its slaves (through trgo). for the stm32f30x and stm32f3x8 the timer can generate two trigger outputs trgo as described below and trgo2 (used for tim and adc synchronization) which can be selected from the following list: ? reset - the ug bit from the egr register is used as trigger output (trgo2). ? enable - the counter enable signal cnt_en is used as trigger output (trgo2). it is useful to start several timers at the same time or to control a window in which a slave timer is enable. the counter enable signal is generated by a logic or between cen control bit and the trigger input when configured in gated mode. ? update - the update event is selected as trigger output (trgo2). for instance a master timer can then be used as a prescaler for a slave timer. ? compare pulse - the trigger output send a positive pulse when the cc1if flag is to be set (even if it was already high), as soon as a capture or a compare match occurred. ? compare - oc1ref signal is used as trigger output (trgo2) ? compare - oc2ref signal is used as trigger output (trgo2) ? compare - oc3ref signal is used as trigger output (trgo2) ? compare - oc4ref signal is used as trigger output (trgo2) ? compare - oc5ref signal is used as trigger output (trgo2) ? compare - oc6ref signal is used as trigger output (trgo2) ? compare pulse - oc4ref rising or falling edges generate pulses on trgo2 ? compare pulse - oc6ref rising or falling edges generate pulses on trgo2 ? compare pulse - oc4ref rising or oc6ref rising edges generate pulses on trgo2 ? compare pulse - oc4ref rising or oc6ref falling edges generate pulses on trgo2 ? compare pulse - oc5ref rising or oc6ref rising edges generate pulses on trgo2 ? compare pulse - oc5ref rising or oc6ref falling edges generate pulses on trgo2
docid022500 rev 4 23/37 AN4013 timer synchronization 36 3.3 slave configuration the slave timer is connected to the master timer through the input trigger. each itrx is connected internally to another timer, and this connection is specific for each stm32 product. the slave mode can be: ? reset mode : rising edge of the selected trigger input (trgi) reinitializes the counter and generates an update of the registers. ? gated mode : the counter clock is enabled when the trigger input (trgi) is high. the counter stops (but is not reset) as soon as the trigger becomes low. both start and stop of the counter are controlled. ? trigger mode : the counter starts at a rising edge of the trigger trgi (but it is not reset). only the start of the counter is controlled. ? external clock mode 1: rising edges of the selected trigger (trgi) clock the counter. ? combined reset + trigger mode - rising edge of the selected trigger input (trgi) reinitializes the counter, generates an update of the registers and starts the counter. this mode is present only for stm32f30xc/bx and stm32f358xc. to configure a timer in slave mode: 1. select the slave mode to be used by writing sms (slave mode selection) bits in smcr register. 2. select the internal trigger to be used by writing ts (trigger selection) bits in smcr register for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/cascade_synchro, /exttrigger_synchro and /parallel_synchro folders.
advanced features for motor control AN4013 24/37 docid022500 rev 4 4 advanced features for motor control 4.1 signal generation the stm32 timer can output two complementary signals and manage the switching-off and the switching-on instants of the outputs. the complementary signals ocx and ocxn are activated by a combination of several control bits: the ccxe and ccxne and the moe, oisx, oisxn, ossi and ossr bits. the main output enable (moe) bit is reset as soon as a break input is active. it is set by software or automatically, depending on the automatic output enable (aoe) bit. when this bit (moe) is reset, the ocx and ocxn outputs are disabled or forced to idle state (oisx oisxn), depending on whether the ossi bit is set or not. note: the moe bit is valid only on the channels that are configured in output. the off-state selection for run mode (ossr) bit is used when moe=1 on channels that have a complementary output configured as outputs. when this bit is set, ocx and ocxn outputs are enabled with their inactive level as soon as ccxe=1 or ccxne=1. the output is still controlled by the timer. the off-state selection for idle mode (ossi) bit is used when moe=0 due to a break event or by a software write, on channels configured as outputs. when this bit is set, ocx and ocxn outputs are first forced with their inactive level, then forced to their idle level after the dead time. the timer maintains its control over the output. table 4 explains the possible configurations of the advanced timer.
docid022500 rev 4 25/37 AN4013 advanced features for motor control 36 note: 1 dead time insertion is enabled by setting both ccxe and ccxne bits, and the moe bit. 2 when only ocxn is enabled (ccxe=0, ccxne=1), it is not complemented and becomes active as soon as ocxref is high. for example, if ccxnp=0 then ocxn=ocxref. on the other hand, when both ocx and ocxn are enabled (ccxe=ccxne=1) ocx becomes active when ocxref is high, whereas ocxn is complemented and becomes active when ocxref is low. table 4. advanced timer configurations control bits output state typical use moe ossi ossr ocxe ocxne ocx output state ocxn output state 1 x 0 0 0 output disable output disable general purpose x 0 0 1 output disable ocxref + polarity x010 ocxref + polarity output disable x011 ocxref + polarity + deadtime (not ocxref) + polarity + deadtime motor control (sinewave) x 1 0 0 output disabled output disabled motor control (6-steps) x 1 0 1 off-state ocxref + polarity x110 ocxref + polarity off-state x111 ocxref + polarity + deadtime (not ocxref) + polarity + deadtime motor control (sinewave) moe ossi ossr ocxe ocxne ocx output state ocxn output state comments 0 0x00 output disable outputs disconnected from i/o ports 0x01 0x10 0x11 1x00 off-state (outputs are first forced with their inactive level then forced to their idle level after the deadtime.) all pwms off (low z for safe stop) 1x01 1x10 1x11
advanced features for motor control AN4013 26/37 docid022500 rev 4 4.2 combined three-phase pwm mode available for stm32f30x and stm32f3x8 the combined three-phase mode allows generating one to three center-aligned pwm signals with a single programmable signal anded in the middle of the pulses. using the 3-bits gc5c[3:1] in the timx_ccr5, each channel of the tim can be a combination between the original signal and the oc5ref signal: ? if gc5c1 is set, oc1 output is controlled by timx_ccr1 and timx_ccr5 ? if gc5c2 is set, oc1 output is controlled by timx_ccr2 and timx_ccr5 ? if gc5c3 is set, oc1 output is controlled by timx_ccr3 and timx_ccr5 the following figure presents an example of this mode figure 5. combined three-phase pwm to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. configure the used channel (1, 2 or/and 3)in pwm mode a) configure the frequency, the duty cycle and the polarity. b) select the pwm 1 or 2. 3. configure the channel 5 in pwm mode with the desired parameter (duty cycle) 4. select the combined pwm mode by programming the gc5cx bits. 5. select the center aligned mode as counting mode 6. enable the capture compare. 7. enable the counter. d^??s kz( k?z( k?z( k?z( kz(}u k?z(}u k?z(}u
docid022500 rev 4 27/37 AN4013 advanced features for motor control 36 for more details on using the timer in this mode, refer to the examples provided in the stm32f30x standard peripheral libraries, in the /project/stm32f30x_stdperiph_examples/ tim/combined folders. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3-discovery\examples\tim\tim_combined, ? projects\stm32303e_eval\examples\tim\tim_combined, ? projects\stm32303c_eval\examples\tim\tim_combined. 4.3 specific features for motor control applications 4.3.1 complementary signal and dead time feature stm32xx advanced timers can generate up to three complementary outputs with insertion of dead time. to use the complementary signal for one channel, set the two output compare enable bits of this channel and its complementary (ocxe and ocxne) channel.if the dead time bits are different from zero, the two signals are generated with insertion of a dead time as illustrated in figure 6: two signals are generated with insertion of a dead time : figure 6. two signals are generated with insertion of a dead time the dead time parameter is computed using the dtg[7:0] bits and the dead time clock (tdtg). the dead time clock is computed as follows: tdtg = tdts, if dtg[7] = 0 tdtg = 2 x tdts, if dtg[6] = 0 tdtg = 8 x tdts, if dtg[5] = 0 tdtg = 16 x tdts, if dtg[7:5] = 111 note: tck_int is the timer internal clock. where: tdts = tck_int, if ckd[1:0] = 00 tdts = 2 x tck_int, if ckd[1:0] = 01 tdts = 4 x tck_int, if ckd[1:0] = 10 069 2&5() &+ &+1 'hod\ 'hod\
advanced features for motor control AN4013 28/37 docid022500 rev 4 the dead time delay is computed using the following formula: dead time = dtg[7:0]x tdtg, if dtg[7] = 0 dead time = (64+dtg[5:0]) x tdtg, if dtg[6] = 0 dead time = (32+dtg[4:0]) x tdtg, if dtg[5] = 0 dead time = (32+dtg[4:0]) x tdtg, if dtg[7:5] = 111 for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/complementarysignals folder. stm32cube f3 firmware includes package examples in the following directories: ? projects\stm32f3-discovery\examples\tim\tim_complementarysignals, ? projects\stm32373c_eval\examples\tim\tim_complementarysignals, ? projects\stm32303e_eval\examples\tim\tim_complementarysignals, ? projects\stm32303c_eval\examples\tim\tim_combined. note: this example is not available for stm32l1 series. 4.3.2 break input the break input is an emergency input in the motor control application. the break function protects power switches driven by pwm signals generated with the advanced timers. the break input is usually connected to fault outputs of power stages and 3-phase inverters. when activated, the break circuitry shuts down the tim outputs and forces them to a predefined safe state. the break event is generated by: ? the brk input that has a programmable polarity and an enable bit bke. ? the css (clock security system). ? software, by setting the bg bit in the egr register. when a break event occurs: ? the moe bit (main output enable) is cleared. ? the break status flag is set and an interrupt request can be generated. ? each output channel is driven with the level programmed in the oisx bit. break inputs in stm32f30x and stm32f3x8 in these lines there are two break inputs break1 and break2. the break can be generated by any of the two brk inputs which have: ? a programmable polarity (bkpx bit in the timx_bdtr register) ? a programmable enable bit (bkex in the timx_bdtr register) ? a programmable filter (bkxf[3:0] bits in the timx_bdtr register) to avoid spurious events. the following table presents the priorities between the two break inputs.
docid022500 rev 4 29/37 AN4013 advanced features for motor control 36 4.3.3 locking mechanism the advanced timers registers and bits can be protected or locked in order to safeguard the application using the locking mechanism by programming the lock bits in the bdtr register. there are three locking levels. note: the lock bits can be written only once after the reset. once the bdtr register has been written, its content is frozen until the next reset. table 5. behavior of timer outputs versus break1 and break2 inputs break input 1 break input 2 ocxn output ocx output active inactive on after deadtime insertion off inactive active off off active - on after deadtime insertion off table 6. locking levels level 1 lock level 2 (1) 1. lock level 2 = lock level 1 + cc polarity bits (ccxp/ccxnp bits in timx_ccer) lock level 3 (2) 2. lock level 3 = lock level 2 + cc control bits (ocxm and ocxpe register bits register bits register bits cr2 oisx cr2 oisx cr2 oisx oisxn oisxn oisxn bdtr dtg[7:0] bdtr dtg[7:0] bdtr dtg[7:0] bke bke bke bkp bkp bkp aoe aoe aoe - bk2e (3) 3. bits present in stm32f30x and stm32f3x8 products lines. ossr ossr - bk2p (3) ossi ossi - bkf[3:0] (3) ccer ccxp ccer ccxp - bk2f[3:0] (3) ccxnp ccxnp - - - - ccmrx ocxm - - - - ocxpe
advanced features for motor control AN4013 30/37 docid022500 rev 4 4.3.4 specific features for feedback measurement encoder modes the incremental encoder is a type of sensor used in motor-control applications to measure the angular position. in general, the incremental encoder generates three signals: phase a, phase b and index. the direction of the motor depends if phase a leads phase b, or phase b leads phase a. a third channel, index pulse, occurs once per revolution and is used as a reference to measure an absolute position. the phase a and b output signals are connected to the encoder interface to compute the frequency and then deduce the velocity and the position. velocity and position information can be measured at x2 or x4 resolution. the following figures explain the encoder interface function. the timer's counter is incremented or decremented for each transition on both inputs ti1 and ti2. figure 7. position at x4 resolution the timer's counter is incremented or decremented for each transition on the selected input ti1 or ti2. 069 iruzdug uhyhuvdo edfnzdug iruzdug uhyhuvdo 'rzq 8s 8s    7, 7, &rxqwhu ',5elw                        
docid022500 rev 4 31/37 AN4013 advanced features for motor control 36 figure 8. position at x2 resolution note: the counter in case of resolution x2 can also be incremented on the ti1 edge. in stm32 timer encoder interface mode, the encoder mode3 corresponds to resolution x4. in this mode, the counter counts up/down on both ti1 and ti2 edges. the resolution x2 is selected when encoder mode 1 or mode 2 is selected, that is, the counter counts up/down on ti2 edge depending on the ti1 level, or the counter counts up/down on ti1 edge depending on ti2 level. how to use the encoder interface an external incremental encoder can be connected directly to the mcu without external interface logic. the third encoder output (index) which indicates the mechanical zero position, may be connected to an external interrupt input and trigger a counter reset. the output signal of the incremental encoder is filtered by the stm32 timer input filter block to reject all noise sources that typically occur in motor systems. this filter is used as described in section 2.3: timer input capture mode . tim configuration in encoder mode 1. select and configure the timer input: ? input selection: ? ti1 connected to ti1fp1 cc1s='01' in ccmr1 register ? ti2 connected to ti2fp2 cc2s='01' in ccmr1 register ? input polarity: ? cc1p='0' and cc1np='0'(ccer register, ti1fp1 non-inverted, ti1fp1=ti1). ? cc2p='0' and cc2np='0'(ccer register, ti1fp2 non-inverted, ti1fp2= ti2). 2. select the encoder mode ? encoder mode1 (resolution x2 on ti2): sms=?001? in smcr register. ? encoder mode2 (resolution x2 on ti1): sms=?010' in smcr register. ? encoder mode3 (resolution x4 on ti1 and ti2): sms=?011? in smcr register. 3. enable the timer counter ? set the counter enable bit, cen='1' in cr1 register. 069 iruzdug uhyhuvdo edfnzdug iruzdug uhyhuvdo 'rzq 8s 8s    7, 7, &rxqwhu ',5elw            
advanced features for motor control AN4013 32/37 docid022500 rev 4 hall sensor the hall sensor is a type of sensor based on hall effect: when a conductor is placed in a magnetic field, a voltage will be generated perpendicular to both the current and the magnetic field. there are four types of hall sensor ic devices that provide a digital output: unipolar switches, bipolar switches, omni polar switches, and latches. the main difference between them is the output waveforms (pulse duration). the digital hall sensor provides a digital output in relation to the magnetic field to which it is exposed. when the magnetic field increases and is greater than the brp (magnetic field release point value), the output will be on. when the magnetic field decreases and is lower than the bop (magnetic field operate point value) the output will be off. figure 9 presents the output waveform of a typical hall sensor. figure 9. output waveform of a typical hall sensor generally, the hall sensor is used in the three-phase motor control. figure 10: commutation sequence presents the commutation sequence. figure 10. commutation sequence how to use the hall sensor interface the stm32 timers can interfaces with the hall effect sensors via the standard inputs (ch1, ch2 and ch3). setting ti1s bit in the cr2 register, allows the input filter of channel 1 to be connected to the output of a xor gate, combining the three input pins timx_ch1, timx_ch2 and timx_ch3. 069 % 2) % 5) 6hqvrurxwsxw 069 0rwrusrvlwlrq +doo +doo +doo            
docid022500 rev 4 33/37 AN4013 advanced features for motor control 36 the slave mode controller is configured in reset mode; the slave input is ti1f_ed. thus, each time one of the 3 inputs toggles, the counter restarts counting from 0. this creates a time base triggered by any change on the hall inputs. channel 1 is configured in input capture mode, capture signal is trc. the captured value, which corresponds to the time, elapsed between 2 changes on the inputs, gives information about motor speed. tim configuration in hall sensor interface mode 1. configure 3 timer inputs ored to the ti1 input channel by writing the ti1s bit in cr2 register to '1', 2. program the time base: write the arr to the max value (the counter must cleared by the ti1 change. set the prescaler to get a maximum counter period longer than the time between 2 changes on the sensors, 3. program channel 1 in capture mode (trc selected): write the cc1s bits in the ccmr1 register to '01'. you can also program the digital filter if needed.
specific applications AN4013 34/37 docid022500 rev 4 5 specific applications 5.1 infrared application the stm32 general-purpose timers can be used to emulate several infrared protocol. an example of this application is explained in application note an3174 ?implementing an rc5 infrared remote control receiver with the stm32f100/101/102/103/105/107 microcontrollers lines. this application note describes a software solution for implementing an rc5 receiver using the stm32 general-purpose timers. 5.2 3-phase ac and pmsm control motor the stm32 advanced and general-purpose timers with adc and dac are used to control two types of 3-phase motor: ac induction motor and pmsm, with different current sensing methodologies: ? isolated current sensing ? three shunt resistors ? single shunt resistor (st patented solution) the stm32 timers are used also in the feedback loop to interface with the different sensors used in the different rotor position feedback: ? tachogenerator ? quadrature encoder ? hall sensors: 60 and 120 placement for more details, please refer to: stm32_pmsm_foc_motorcontrol_fmlib. 5.3 six-step mode the six step mode is a specific mode of stm32 advanced timers. when complementary outputs are used on a channel, preload bits are available on the ocxm, ccxe and ccxne bits. the preload bits are transferred to the shadow bits at the com (commutation event). thus you can program in advance the configuration for the next step and change the configuration of all the channels at the same time. com can be generated by software by setting the com bit in the egr register or by hardware (on trgi rising edge). an application example of the use of this mode is the control of the brush-less 3-phase dc motor (3-phase bldc motor).
docid022500 rev 4 35/37 AN4013 specific applications 36 configuring the timer to generate a six step signal to control a brush-less 3- phase dc motor (3-phase bldc motor): ? time base configuration: prescaler, period, clock source ? channels 1, 2, 3 and 4 configured in pwm mode ? set the capture compare preload control bit ccpc ? enable the commutation interrupt source ? use the system tick to generate time base ? each commutation event, the tim configuration is updated for the next commutation event. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/6steps folder. note: this example is not available for stm32l1 series.
revision history AN4013 36/37 docid022500 rev 4 6 revision history table 7. document revision history date revision changes 21-feb-2012 1 initial release. 22-oct-2012 2 added support for stm32f30x, stm32f31x, stm32f37x, stm32f38x. 12-feb-2014 3 added support for stm32f0 series, stm32f358xc. replaced ?basic timers? by ?general-purpose? timers in the whole document. updated section 2.1.2: external clock . updated section 2.4: timer output compare mode . updated section 2.5: timer pwm mode . updated section 5.3: six-step mode . 28-jan-2015 4 extended the applicability to stm32f303xdxe. updated: ? table 1: applicable products ? table 2: stm32 family timers ? the document title and introduction added references to timer examples available in stm32cube f3 firmware package where applicable.
docid022500 rev 4 37/37 AN4013 37 important notice ? please read carefully stmicroelectronics nv and its subsidiaries (?st?) reserve the right to make changes, corrections, enhancements, modifications, and improvements to st products and/or to this document at any time without notice. purchasers should obtain the latest relevant in formation on st products before placing orders. st products are sold pursuant to st?s terms and conditions of sale in place at the time of o rder acknowledgement. purchasers are solely responsible for the choice, selection, and use of st products and st assumes no liability for application assistance or the design of purchasers? products. no license, express or implied, to any intellectual property right is granted by st herein. resale of st products with provisions different from the information set forth herein shall void any warranty granted by st for such product. st and the st logo are trademarks of st. all other product or service names are the property of their respective owners. information in this document supersedes and replaces information previously supplied in any prior versions of this document. ? 2015 stmicroelectronics ? all rights reserved


▲Up To Search▲   

 
Price & Availability of AN4013

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X